package com.ruoyi.web.controller.cs;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.payment.SanjinCallbackReq;
import com.ruoyi.common.payment.YukuaiqiCallbackReq;
import com.ruoyi.cs.service.payment.SanjinService;
import com.ruoyi.cs.service.payment.YukuaiqiService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/cs/callback")
@Slf4j
public class PayCallbackController {
    @Autowired
    private YukuaiqiService yukuaiqiService;
    @Autowired
    private SanjinService sanjinService;

    @PostMapping("/yukuaiqiNotify")
    @Log(title = "yukuaiqi支付充值异步回调", businessType = BusinessType.OTHER)
    public String yukuaiqiNotify(@RequestBody YukuaiqiCallbackReq vo) {
        try {
            return yukuaiqiService.notify(vo);
        } catch (Exception e) {
            log.error("yukuaiqi支付异步通知异常:{},参数:{}", e.getMessage());
            return "fail";
        }
    }

    @PostMapping("/sanjinNotify")
    @Log(title = "sanjin支付充值异步回调", businessType = BusinessType.OTHER)
    public String sanjinNotify(HttpServletRequest request) {
        try {
            return sanjinService.notify(request);
        } catch (Exception e) {
            log.error("三斤支付异步通知异常:{}", e);
            return "fail";
        }
    }
}
